package JUC;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo01 {
    static int num = 0;

    public synchronized static void test(){
        num++;
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0;i<20;i++){
            new Thread(() -> {
                for (int n = 0;n< 1000;n++){
                    test();
                }
                System.out.println(Thread.currentThread().getName() + " " + num);
            }).start();
        }
        TimeUnit.SECONDS.sleep(1);
        System.out.println(Thread.currentThread().getName()+" "+ num );
    }
}
